﻿using NuMvvm.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuMvvm.Testing.Services
{
    public class MockWindowService : IWindowService
    {
        public IDialogWindow CurrentDialog
        {
            get
            {
                return CurrentWindow as IDialogWindow;
            }
        }

        public IWindow CurrentWindow
        {
            get;
            private set;
        }
        public bool? MockDialogResult { get; set; }

        public void Show(object window)
        {
            CurrentWindow = new MockWindow(window);
        }

        public void Show(object window, object arg)
        {
            CurrentWindow = new MockWindow(window, arg);
        }

        public bool? ShowDialog(object window)
        {
            CurrentWindow = new MockDialogWindow(window);
            return MockDialogResult;
        }

        public bool? ShowDialog(object window, object arg)
        {
            CurrentWindow = new MockDialogWindow(window, arg);
            return MockDialogResult;
        }
    }

    public class MockWindow : IWindow
    {
        private object arg;
        private object view;

        public MockWindow(object view)
        {
            this.view = view;
        }

        public MockWindow(object view, object arg) : this(view)
        {
            this.arg = arg;
        }

        public object Argument
        {
            get
            {
                return arg;
            }
        }

        public object View
        {
            get
            {
                return view;
            }
        }

        public object DataContext
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsClosed { get; private set; }

        public void Close()
        {
            IsClosed = true;
        }
    }

    public class MockDialogWindow : MockWindow, IDialogWindow
    {
        public MockDialogWindow(object view) : base(view)
        {

        }

        public MockDialogWindow(object view, object arg) : base(view, arg)
        {

        }

        public void Close(bool? result)
        {
            
        }
    }
}
